<?php

namespace app\controller\sys;

use app\BaseController;
use app\model\SysUploadFiles;
use think\Response;

class Image extends BaseController
{
    public function lst(): Response
    {
        $data = $this->app->make(SysUploadFiles::class)->order("create_time desc")->paginate([
            'list_rows' => $this->request->param("size", 30),
            'page' => $this->request->param("page", 1)
        ])->toArray();
        return $this->success(pageData($data));
    }

    public function delete(): Response
    {
        $data = $this->app->make(SysUploadFiles::class)->where('id', $this->request->param("id"))->find();
        if (empty($data)) throw new \Exception("图片不存在", 7001);
        @unlink($data->dir);
        $data->delete();
        return $this->success();
    }
}
